package com.example.demo.web.controller;

import com.example.demo.bean.Interfaces;
import com.example.demo.service.IInterfacesService;
import com.example.demo.utils.Message;
import com.example.demo.utils.MessageUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@Validated
@RequestMapping("/interfaces")


public class InterfacesController {

    @Autowired
    private IInterfacesService interfacesService;

    @GetMapping("query")
    public Message query( Long id,String name){
        List<Interfaces> list = interfacesService.query(id,name);
        return MessageUtil.success(list);
    }

    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Interfaces info){
        interfacesService.saveOrUpdate (info);
        return MessageUtil.success("操作成功");
    }

    @DeleteMapping("deleteById")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="id", value ="用户编号",required = true,paramType = "query"),
    })
    public Message deleteById(@NotNull Long id){
        interfacesService.deleteById(id);
        return MessageUtil.success("操作成功");
    }
}


